package com.topisv.tms.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.ErpTMS;
import com.topisv.tms.repository.ErpTMSDao;

//Spring Bean的标识.
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class ErpTMSService {

	@Autowired
	private ErpTMSDao erpTMSDao;

	@Transactional(readOnly = false)
	public ErpTMS saveErpTMS(ErpTMS erpTMS) {
		if (erpTMS == null) {
			throw new IllegalArgumentException("erpTMS=" + erpTMS);
		}
		return erpTMSDao.save(erpTMS);
	}

	public List<ErpTMS> getMaxErpTMS() {
		List<Long> ids = erpTMSDao.getMaxErpTMSId();
		List<ErpTMS> erpTMSs = new ArrayList<ErpTMS>();
		if (ids != null) {
			int length = ids.size();
			for (int i = 0; i < length; i++) {
				ErpTMS erpTMS = erpTMSDao.getMaxErpTMS(ids.get(i));
				erpTMSs.add(erpTMS);
			}
		}
		return erpTMSs;
	}
}
